cap log close
clear all

if c(username) == "matteobobba" {
	global JPE `"/Users/matteobobba/Dropbox/Research/API/Submissions/1. JPE/5. June 2024"'
	}


**************************************
/* Table A-1: LEC Characteristics */
**************************************

use "${JPE}/Data/survey_teachers.dta", clear		

local teachers "l_age l_male l_lessthanuppersec_2 l_uppersec_2 l_aboveuppersec_2 l_experience_months_2 l_trainingweeks_2 l_time_school_2 l_resident_community_2 l_nights_community_2"

gen birthdate = date(P3, "MDY")
format birthdate %td

gen encdate = date(Fecha_aplicacion, "MDY")
format encdate %td

gen age=(encdate -  birthdate)/365.25
replace age=. if age<15
rename age l_age

gen l_male=(P2==1)

label var l_age "Age"
label var l_male "Male"
label var l_lessthanuppersec_2 "Lower than Upper Second" 
label var l_uppersec_2 "Upper Second Complete" 
label var l_aboveuppersec_2 "Above Upper Second"
label var l_trainingweeks_2 "Training Weeks at Baseline" 
label var l_experience_months_2 "Experience in Months" 
label var l_time_school_2 "Time spent in the School"
label var l_resident_community_2 "Sleeps in the Community"
label var l_nights_community_2 "Nights spent in the Community"
		

balancetable (mean if fulllec==1) (mean if fulllec==0) (diff fulllec) ///
		`teachers' using "${JPE}/Draft/Tables/table_a1.tex", groups("Original Survey" "2022 Survey" "Difference")  varlabels nohead nonumbers replace

*************************************
/* Table A-2: API Characteristics */		
*************************************	
use "${JPE}/Data/survey_mentors.dta", clear

	

local myvars "mt_age_2 mt_male_2 mt_uni_2 mt_weeks_training_current_2 mt_weeks_training_anterior_2 mt_experience_api_2 mt_lec_2 mt_asistente_educativo_2 mt_days_community_A_2 mt_days_stay_A_2 mt_ind_lv_2 mt_lec_planning_2 mt_lec_studycase_2 mt_lec_1to1tutor_2 mt_lec_helpmaterial_2 mt_time_parents_2 mt_culture_2 mt_communication_2 mt_feelings_2 mt_selfknowledge_2 mt_learning_2"


label var mt_age_2 "Age"
label var mt_male_2 "Male"
label var mt_uni_2 "High Edu Complete"
label var mt_weeks_training_current_2 "Training Weeks Current" 
label var mt_weeks_training_anterior_2 "Training Weeks Previous Cycle" 
label var mt_experience_api_2 "Experience as Api" 
label var mt_lec_2 "Previous LEC"
label var  mt_asistente_educativo_2 "Education Assistant"
label var  mt_days_community_A_2 "Days in Community A"
label var  mt_days_stay_A_2 "Days Stay A"
label var  mt_ind_lv_2 "Students Lagging Behind"
label var  mt_time_ind_lv_2  "Time students 1to1"
label var  mt_time_adv_lv_2  "Time students lagging behind"
label var  mt_lec_planning_2 "Help LEC with Planning (Y/N)"
label var  mt_lec_studycase_2 "Help LEC with study cases (Y/N)"
label var  mt_lec_1to1tutor_2 "Help LEC pers sess (Y/N)"
label var  mt_lec_helpmaterial_2 "Help LEC prepare material (Y/N)"
label var mt_time_parents_2 "Time with Parents" 
label var mt_culture_2 "Topic: Culture" 
label var mt_communication_2 "Topic: Communication" 
label var mt_feelings_2 "Topic: Feelings" 
label var mt_selfknowledge_2 "Topic: Self"
label var mt_learning_2 "Topic: Learning" 


balancetable (mean if fullapi==1) (mean if fullapi==0)   (diff fullapi)   ///
		`myvars' using "${JPE}/Draft/Tables/table_a2.tex", groups("Original Survey" "2022 Survey" "Difference") varlabels nohead nonumbers replace

		
*******************************************************************************************************************************************************
/* Figure B1: Treatment Effects on Secondary School Enrollment During the Transition Between the Second Experiment and the Government Implementation */
*******************************************************************************************************************************************************
use "${JPE}/Data/exp2.dta", clear

forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

qui reg st_enroll_sec_3   i.sc_strata1_0  sc_cal_* treat1 treat2  st_male_tr_3  , cluster(cct)
est store enroll_rf
coefplot enroll_rf ,vertical  color(emerald)    coeflabels(treat1="API Original" treat2="API Plus") levels(90 95) keep(treat1 treat2) yline(0, lpattern(dash)) graphregion(color(white))  msymbol(d) legend(order(1 "Point Estimate" 2 "90% CI" 3 "95% CI") row(1))  ytitle(Treat Effect on Secondary School Enrollment) xtitle(Treatment Assignment -- Second Experiment) recast(bar) ciopts(recast(rcap)) citop barwidt(0.3)  
graph export "${JPE}/Draft/Figures/fig_b1.eps", replace



		
****************************************************************************************
/* Figure B2: The Cumulative Effect of API Plus in the Experimental Sample of Schools */
****************************************************************************************	 
	
use "${JPE}/Data/exp2.dta", clear
 
forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

qui ta sc_criterios_3, m gen(crite_3_)	 
qui ta sc_criterios_4, m gen(crite_4_) 
	 	 

gen d_missing_exposure = 0 if y_exposure!=. & y_exposure>0
replace d_missing_exposure = 0 if d_treat_3!=. & y_exposure==0
replace d_missing_exposure = 1 if d_treat_3==. & y_exposure==0
	 
gen sc_yexposure1617_plus = sc_yexposure1617 if treat==0 | treat==2
replace sc_yexposure1617_plus = sc_yexposure1617 - 2 if treat==1
label var sc_yexposure1617_plus "Years of Exposure to API Plus"

label define sc_yexposure1617_plus 0 "0 Years" 1 "1 Year " 2 "2 Years" 3 "3 Years"  
label values sc_yexposure1617_plus sc_yexposure1617_plus 

qui sum st_enroll_sec_3 if sc_yexposure1617_plus==0
local national_level = 0.95 - r(mean)

qui reg st_enroll_sec_3   treat1 i.sc_yexposure1617_plus  i.sc_strata1_0 sc_cal_*  crite_3_* d_missing_exposure st_male_tr_3, cluster(cct) 
estimates store exposure_plus_enroll_sec
coefplot exposure_plus_enroll_sec ,vertical  text( 0.4 0.9  "National Average" , color(red) ) color(emerald)   levels(90 95) keep( 1.sc_yexposure1617_plus 2.sc_yexposure1617_plus 3.sc_yexposure1617_plus  )   yline(  `national_level', lpattern(solid) lcolor(red) ) yline(0  , lpattern(dash) ) graphregion(color(white))  msymbol(d) legend(order(1 "Point Estimate" 2 "90% CI" 3 "95% CI") row(1))  ytitle(Treatment Effect on Transition to Secondary) xtitle(Total Years of Exposure to API Plus) ylabel(-0.1(.1)0.5) recast(bar) ciopts(recast(rcap)) citop barwidt(0.3)  
graph export "${JPE}/Draft/Figures/fig_b2.eps", replace


***************************************************************************************
/* Figure B3: Probability of Being in Remedial Sessions by Inverted Achievement Rank */
***************************************************************************************
use "${JPE}/Data/exp2.dta", clear

ren st_st_spanishscore_1_2 st_spanishscore_1 
ren st_st_mathscore_1_2 st_mathscore_1 
ren st_st_natsciences_1_2 st_natscore_1

local list1 "st_spanishscore_1 st_mathscore_1 st_natscore_1" 

egen mean_score=rowmean(`list1')
bys cct: egen rank_avg=rank(mean_score), track
label var rank_avg "Rank"


label var mean_score "Average score in the three subjects Spanish/Mat/Natural Science"
gen mean_score_sq=(mean_score*mean_score)/10
label var mean_score_sq "Average mean score square"


qui probit pp_focalizado i.rank_avg if (treat==1 | treat==2) 
qui margins, dydx(*) predict(pr) post
coefplot, drop(_cons) xline(0) graphregion(color(white))
graph export "${JPE}/Draft/Figures/fig_b3.eps", replace

**********************************************************************************
/* Table B-1: Baseline Characteristics and Covariate Balance – First Experiment */
**********************************************************************************

use "${JPE}/Data/exp1_schools_app.dta", clear
drop if treat==.
merge n:1 ID02 using "${JPE}/Data/exp1_parents_app.dta"
gen smpl_parent=_m==3
drop _m
merge n:1 ID02 using "${JPE}/Data/exp1_students_app.dta"
gen smpl_stud=_m==3
drop _m


replace ANAL10=ANAL10/100
replace PISOTIE10=PISOTIE10/100

label var ANAL10 "Share of analphabet population"
label var PISOTIE10 "Share of dwellings with dirt floor" 
label var api_fortalece "In API and Fortalece sample"

label variable share_overage2010 "Share over-aged students"
label variable enrollment2010 "Enrollment"
label variable teachers2010 "Number of Teachers"
label variable enl_spanish_2010 "ENLACE Spanish 2010"
label variable enl_math_2010 "ENLACE Math 2010 " 

local school "enl_spanish_2010 enl_math_2010 enrollment2010 teachers2010 share_overage2010"
local community "vivtot pobtot rpea water_connection sewer_system ANAL10 PISOTIE10 garbage_coll"

keep if smpl_parent==1
balancetable (mean if treat==1) (mean if treat==0) (diff treat) `community' `school' using "${JPE}/Draft/Tables/table_b1a.tex", fe(ent) pvalues varlabels nohead nofoot wide(mean sd mean sd pval mean sd mean sd pval) nopar replace

keep if smpl_stud==1
balancetable (mean if treat==1) (mean if treat==0) (diff treat) `community' `school' using "${JPE}/Draft/Tables/table_b1b.tex", fe(ent) pvalues varlabels nohead nofoot wide(mean sd mean sd pval mean sd mean sd pval) nopar replace

***********************************************************************************
/* Table B-2: Baseline Characteristics and Covariate Balance – Second Experiment */
***********************************************************************************
use "${JPE}/Data/exp2_teachers.dta", clear

gen indig=P4_0==0
replace indig=. if P4_0==.

gen secu_less=P5==5|P5==6
replace secu_less=. if P5==.

gen secu=P5==7
replace secu=. if P5==.

gen coll_some=P5==8|P5==9
replace coll_some=. if P5==.

ren P7_A exp_yr
gen exp_school_month=(12*P8_A)+P8_M


global lec secu exp_yr exp_school_month

collapse $lec treat strata1, by(cct)

label var secu "Secundary Education"
label var exp_yr "Years of Experience as Teacher" 
label var exp_school_month "Months Working in That School" 

merge 1:1 cct using "${JPE}/Data/exp2_schools.dta", keep(3) nogen


balancetable (mean if treat1==0&treat2==0) (mean if treat1==1) (mean if treat2==1) (diff treat1 if treat2!=1) (diff treat2 if treat1!=1) $lec  using "${JPE}/Draft/Tables/table_b2teacher.tex" , vce(cluster cct) covariates(i.strata1) varlabels pval  nohead replace


use "${JPE}/Data/exp2_individual.dta", clear
drop _m

sort cct
keep if cct!=cct[_n-1]
merge 1:1 cct using "${JPE}/Data/exp2_schools.dta", keep(3) nogen


global school spanish_enlace math_enlace science_enlace docentes matricula

label variable aulas_uso "Rooms in Use"  
label variable aulas_ex "Rooms School"
label variable docentes "Number of Teachers" 
label variable matricula "Number of Students" 
label variable spanish_enlace "Average Test Score (Spanish)"
label variable math_enlace "Average Test Score (Math)" 
label variable science_enlace "Average Test Score (Science)"  

generate treatment_A = (treat==1)
generate treatment_B = (treat==2)

balancetable (mean if treat==0) (mean if treat==1) (mean if treat==2) (diff treatment_A if treat!=2) (diff treatment_B if treat!=1) $school using "${JPE}/Draft/Tables/table_b2school.tex" , vce(cluster cct) covariates(i.strata1) varlabels pval nofoot nohead replace

		
use "${JPE}/Data/exp2_individual.dta", clear
drop _m
keep if ID!=""
merge 1:1 ID using "${JPE}/Data/Appendix/exp2_students.dta", keep(3) nogen

 
label var age_b "Age in Months at Baseline (September 2014)"
label var male "Male (Y/N)"
label var indig_lang "Indigenous Language (Y/N)"
label var scholarship "Scholarship (Y/N)" 


global individual age_b male indig_lang scholarship 

use "${JPE}/Data/exp2_parents.dta", clear
merge 1:1 ID using "${JPE}/Data/exp2_students.dta", keep(3) nogen
 

global parents read less_primary /*upper_sec_or_higher */
global household  Oport   /* sewagerefrigerator television car phone light */ 

sum $parents
sum $household
generate treatment_A = (treat==1)
generate treatment_B = (treat==2)


label variable read  " Parent Can Read "
label variable less_primary  " Parent with Less than Primary "
label variable Oport  " Household Receives Oportunidades CCT "


balancetable (mean if treat==0) (mean if treat==1) (mean if treat==2) (diff treatment_A if treat!=2) (diff treatment_B if treat!=1) $individual $parents $household using "${JPE}/Draft/Tables/table_b2indiv.tex" , covariates(i.strata1)  vce(cluster cct) pval  varlabels nohead  replace



use "${JPE}/Data/exp2_mentors.dta", clear
merge n:1 cct using "${JPE}/Data/exp2_school_api.dta", keep(3) nogen


global apivars age male uni  experience_api  

label var age "Age in Years"
label var male "Male"
label var uni "High Edu Complete"
label var experience_api "Months of Experience as Mentor" 

balancetable (mean if mt_Plus_2==0) (mean if mt_Plus_2==1)   (diff  mt_Plus_2)  $apivars using "${JPE}/Draft/Tables/table_b2mentors.tex" , vce(cluster cct) covariates(i.strata1) varlabels pval  nohead replace



*******************************************************************************
/* Table B-3: Treatment Assignment and School-Level Student Composition */
*******************************************************************************

use "${JPE}/Data/exp2.dta", clear

cap estimates clear
label var st_repeater_1 "Repeater end of SY 2014-2015"
label var st_repeater_2 "Repeater end of SY 2015-2016"
label var st_outsidesystem_1 "Coming from SEP system"
label var st_same_cct "Same school in 2014-2015 & 2015-2016"
label var st_dropout "Drop-out between 2014-2015 and 2015-2016"

gen treat1=(treat==1)
gen treat2=(treat==2)

qui xi: reg st_repeater_2 treat1 treat2 st_male_2 st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if (merge_ind_par==3)
gen sample=e(sample)


foreach x of varlist st_repeater_2 st_dropout st_outsidesystem_1 st_same_cct {
label var treat1 "API Standard" 
label var treat2 "API Plus" 
qui xi: reg `x' treat1 treat2 st_male_2 st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if (merge_ind_par==3 & sample==1), vce(cl cct)
qui sum `x' if e(sample) & treat==0
qui estadd scalar mean = r(mean)
qui estadd scalar sd=r(sd)
qui estadd scalar obs = e(N)
qui estadd scalar clusters = e(N_clust)
qui test treat1=treat2
qui estadd scalar pval_t=r(p)
eststo ols`x'  
}



estout olsst_repeater_2 olsst_dropout olsst_outsidesystem_1 olsst_same_cct using "${JPE}/Draft/Tables/table_b3.tex", replace style(tex) cells(b(star fmt(%9.3f)) p(par([ ])))   stats(pval_t obs clusters, fmt(%9.3f %9.0g %9.0g) labels("p-value H0: API Standard=API Plus" "Observations" "Clusters")) mlabel("Repeater end of SY 2015-2016" "Drop-out between 2014-2015 and 2015-2016" "Coming from SEP system" "Same school in 2014-2015 & 2015-2016") starlevels(* 0.10 ** 0.05 *** 0.01) label collabels(none)  varlabels(treat1 "API Standard"  treat2 "API Plus")  keep(treat1 treat2) 

 
*******************************************************************************
/* Table B-4: Differences Between Overall Samples and Matched-census Samples */
*******************************************************************************
use "${JPE}/Data/scaleup_localities.dta", clear

drop if sample==3

*merge m:1 cct using "$data/exp2_schools.dta", keepusing(cct) keep(1) nogen
* 1,243 non-experimental schools in Chiapas

merge m:1 cct using "${JPE}/Data/exp2_schools_reg.dta", keep(1 3) nogen

gen nonexp_sch=. if sample==1
replace nonexp_sch=1 if nonexp==1&sample==1
replace nonexp_sch=0 if exp==1&sample==1

expand 2

bys cct sample: gen chiapas=_n-1 

replace chiapas=. if (chiapas==1&nonexp==0&sample==1)|(chiapas==1&nonexp==.&sample==1)

gen chiap=1-chiapas

bys cct sample: gen exper=_n-1
 
replace exper=. if (exper==1&exp!=1&sample==1)

gen sampl=sample==2

global enlace10 cal_esp10 cal_mat10 
global school2012 repeat2012 overage2012 enrollment2012 teachers2012
global loc poverty_high confl_d share_illi share_econ noroad paved_road pobtot water sewer waste


balancetable (mean if sample==1&chiapas==0) (mean if sample==1&chiapas==1) (diff chiap if sample==1) (mean if sample==2&exper==1) (mean if sample==1&exper==1) (diff sampl if exper==1) $enlace10 $school2012 $loc  using "${JPE}/Draft/Tables/table_b4.tex", varlabels pval vce(robust) ctitles("All Chiapas" "Second Experiment" "All vs Experiment 2" ) replace


***********************************************************************************
/* Table B-5: Heterogeneity in the Impact of the Program by Eligibility Criteria */
***********************************************************************************
use "${JPE}/Data/exp2.dta", clear

swindex st_egra_2 st_egma_2 st_tot_dum_e_2 if merge_ind_par==3, gen(st_index_2)

foreach x of varlist st_egra_2 st_egma_2 st_tot_dum_e_2 st_index_2 {
	gen `x'_sd = .
	qui sum `x' if treat==0  & merge_ind_par==3
	replace `x'_sd =(`x'-r(mean))/r(sd) 
	}

swindex sc_cal_espMine_0 sc_cal_matMine_0, gen(sc_cal_index)

foreach x in sc_cal_esp sc_cal_mat sc_cal_fce sc_cal_index{
	cap ren `x'Mine_0 `x'
	gen `x'_sd = .
	qui sum `x' if merge_ind_par==3
	replace `x'_sd =(`x'-r(mean))/r(sd) 
	}
	
gen cruz=CNCH_405=="OK"
gen marg=sc_grs_0=="Alto"|sc_grs_0=="Muy Alto"
gen marg_miss=sc_grs_0==""

forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

forvalues j = 1(1)2{
	gen treat`j'Xmarg = treat`j'*marg
	gen treat`j'Xmarg_miss = treat`j'*marg_miss
	gen treat`j'Xcruz = treat`j'*cruz
	*gen treat`j'Xcal_esp = treat`j'*sc_cal_esp_sd
	gen treat`j'Xcal_index = treat`j'*sc_cal_index
	*gen treat`j'Xcal_fce = treat`j'*sc_cal_fce_sd

}


qui xi: reg st_index_2_sd treat1 treat2 treat1X* treat2X*  st_male_2  st_ind_lang_2 sc_cal_esp_sd sc_cal_mat_sd sc_cal_fce_sd i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3,  vce(cl cct)
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui test treat1Xmarg=treat1Xcruz=treat1Xcal_index
	qui estadd scalar pval_std=r(p)
	qui test treat2Xmarg=treat2Xcruz=treat2Xcal_index
	qui estadd scalar pval_plus=r(p)
	qui sum st_index_2_sd if e(sample) & treat==0
	qui estadd scalar mean_yes = r(mean)
	eststo st_index_2_sd  
	
	
qui reg st_enroll_sec_2 treat1 treat2 treat1X* treat2X* st_age_tr_2 st_male_tr_2   sc_cal_esp_sd sc_cal_mat_sd sc_cal_fce_sd  i.sc_strata1_0 , vce(cl cct)
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui test treat1Xmarg=treat1Xcruz=treat1Xcal_index
	qui estadd scalar pval_std=r(p)
	qui test treat2Xmarg=treat2Xcruz=treat2Xcal_index
	qui estadd scalar pval_plus=r(p)
	qui sum st_enroll_sec_2 if e(sample) & treat==0
	qui estadd scalar mean_yes = r(mean)
	eststo st_enroll_sec_2
	
estout   st_index_2_sd st_enroll_sec_2 using "${JPE}/Draft/Tables/table_b5.tex", replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ])) .) stats(pval_std pval_plus obs clusters, layout("[@]" "[@]" "") fmt(%9.3f %9.3f %9.0g %9.0g) labels("API Original(Poverty)=API Original(Welfare)=API Original(Math Z-score)" "API Plus(Poverty)=API Plus(Welfare)=API Plus(Z-score)" "" "Observations" "Clusters")) starlevels(* 0.10 ** 0.05 *** 0.01) label collabels(none)     mlabels(none) varlabels(treat1 "API Original" treat1Xmarg "API Original$\times$ Poverty" treat1Xcruz "API Original$\times$ Welfare" treat1Xcal_index "API Original$\times$ Z-score" treat2 "API Plus"  treat2Xmarg "API Plus$\times$ Poverty" treat2Xcruz "API Plus$\times$ Welfare" treat2Xcal_index "API Plus$\times$ Z-score")   keep(treat1 treat2 treat*Xmarg treat*Xcruz treat*Xcal_index)  order(treat1* treat2*)


***************************************************************************************
/* Table B-6: Program Assignment at Scale (2017-2018) and Observable Characteristics */
***************************************************************************************
use "${JPE}/Data/scaleup_localities.dta", clear

drop if sample==3

merge m:1 cct using "${JPE}/Data/exp2_schools_reg.dta", keep(1 3) nogen

keep if sample==1&(exp==1|nonexp==1)

balancetable (mean if api_1718_new==1) (mean if api_1718_new==0) (diff api_1718_new) $enlace10 $school2012 $loc  using "${JPE}/Draft/Tables/table_b6.tex", covariates(confl_sum i.api_original_2015 i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718)) varlabels pval vce(robust) ctitles("API Plus" "No Program" "API Plus vs No Program" ) replace

* Joint Null Hypothesis
qui reg api_1718_new $enlace10 $school2012 $loc confl_sum i.api_original_2015 i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718)  , r
test $enlace10 $school2012 $loc

*****************************************************************************	 
/* Table B-7: Placebo Test for API Plus Assignment During Program Scale-up */
*****************************************************************************	
use "${JPE}/Data/scaleup.dta", clear

ren sc_cal_espMine_0 enla_esp
ren sc_cal_matMine_0 enla_mat
ren sc_cal_fceMine_0 enla_fce

foreach y in enla_esp enla_mat enla_fce {

qui sum `y'
gen `y'_sd = (`y' - r(mean))/r(sd)
}

local reps=3000
local seed=123
qui rwolf2 (reg enla_esp_sd api_1718_new if enr_sec_2020!=., r)  (reg enla_mat_sd api_1718_new if enr_sec_2020!=., r) (reg enla_fce_sd api_1718_new if enr_sec_2020!=., r) , indepvars(api_1718_new, api_1718_new , api_1718_new) usevalid seed(`seed') reps(`reps') nodots 
mat RW_no=e(RW)

qui rwolf2 (reg enla_esp_sd api_1718_new  i.api_original_2015 confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if enr_sec_2020!=., r)  (reg enla_mat_sd api_1718_new  i.api_original_2015 confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if enr_sec_2020!=., r) (reg enla_fce_sd api_1718_new  i.api_original_2015 confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if enr_sec_2020!=., r) , indepvars(api_1718_new, api_1718_new , api_1718_new) usevalid seed(`seed') reps(`reps') nodots 
mat RW_yes=e(RW)


local k=1

foreach x of varlist enla_esp_sd enla_mat_sd enla_fce_sd{
	qui reg `x' api_1718_new if enr_sec_2020!=., r		
	qui estadd scalar obs = e(N)
	qui eststo `x'_no 
	
	qui reg `x' api_1718_new  i.api_original_2015 confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if enr_sec_2020!=., r		
	qui estadd scalar obs = e(N)
	qui eststo `x'_yes 
	
	qui ritest api_1718_new _b[api_1718_new]/_se[api_1718_new] , seed(`seed') reps(`reps') nodots: reg `x' api_1718_new if enr_sec_2020!=., r
	qui matrix ri=r(p)
	qui mat colnames ri = api_1718_new
	qui mat rw=RW_no[`k',3]
	qui mat colnames rw = api_1718_new
	qui est restore `x'_no
	qui estadd mat p_ri=ri
	qui estadd mat p_rw=rw
	qui eststo `x'_no

	qui ritest api_1718_new _b[api_1718_new]/_se[api_1718_new] , seed(`seed') reps(`reps') nodots: reg `x' api_1718_new  i.api_original_2015 confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if enr_sec_2020!=., r
	qui matrix ri=r(p)
	qui mat colnames ri = api_1718_new
	qui mat rw=RW_yes[`k',3]
	qui mat colnames rw = api_1718_new
	qui est restore `x'_yes
	qui estadd mat p_ri=ri
	qui estadd mat p_rw=rw
	qui eststo `x'_yes
	 
	local k=`k'+1
	
} 


estout enla_esp_sd_no enla_esp_sd_yes  enla_mat_sd_no  enla_mat_sd_yes  enla_fce_sd_no  enla_fce_sd_yes using "${JPE}/Draft/Tables/table_b7.tex",  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]) fmt(%9.3f))  p_ri(par(\{  \}) fmt(%9.3f)) p_rw(par(( )) fmt(%9.3f)) .)  stats(obs , fmt( %9.0g ) labels("Observations" ))  label collabels(none)  mlabels(none) varlabels(api_1718_new "API Plus ")   keep(api_1718_new) 


****************************************************************************************	 
/*Table B-8: Average Program Impacts by Subdomains of the Reading and the Math Scores */
****************************************************************************************
use "${JPE}/Data/exp2.dta", clear

forvalues j = 0(1)2{
	gen treat`j' = 0
	replace treat`j' = 1 if treat==`j'
	replace treat`j' = . if treat==.
}

foreach x of varlist st_tot_letters1_2 st_tot_letters2_2 st_tot_letters3_2 st_tot_letters4_2 st_tot_letters5_2 st_tot_letters6_2 st_tot_letters7_2 st_tot_letters8_2 st_tot_num1_2 st_tot_num2_2 st_tot_num3_2 st_tot_num4a_2 st_tot_num4b_2 st_tot_num5_2 st_tot_num6_2{
	gen `x'_sd = .
	qui sum `x' if treat==0  & merge_ind_par==3
	replace `x'_sd =(`x'-r(mean))/r(sd) 
}

local reps=3000
local seed=123

qui rwolf2 (reg st_tot_letters1_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters2_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters3_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters4_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters5_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters6_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters7_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters8_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) , cluster(cct) indepvars(treat1, treat1, treat1,treat1,treat1,treat1,treat1,treat1) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_stand=e(RW)

qui rwolf2 (reg st_tot_letters1_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters2_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters3_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters4_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters5_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters6_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters7_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters8_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct))	, cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_plus=e(RW)

qui rwolf2 (reg st_tot_letters1_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters2_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters3_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters4_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters5_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters6_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters7_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_letters8_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct))	, cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_diff=e(RW)


local k=1

foreach x of varlist st_tot_letters1_2_sd st_tot_letters2_2_sd st_tot_letters3_2_sd st_tot_letters4_2_sd st_tot_letters5_2_sd st_tot_letters6_2_sd st_tot_letters7_2_sd st_tot_letters8_2_sd {
	qui reg `x' treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)			
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui estadd scalar adjR2 = e(r2_a)
	qui test treat1=treat2
	qui estadd scalar p_diff=r(p)
	qui sum `x' if e(sample) & treat==0
	qui estadd scalar mean = r(mean)
	qui estadd scalar sd=r(sd)
	qui eststo `x' 

	qui ritest treat _b[1.treat]/_se[1.treat] , fixlevels(2) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt1=r(p)
	qui mat colnames pt1 = treat1
	qui mat p_stand=RW_stand[`k',3]
	qui mat colnames p_stand = treat1
	
	qui ritest treat _b[2.treat]/_se[2.treat] , fixlevels(1) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt2=r(p)
	qui mat colnames pt2 = treat2 
	qui mat p_plus=RW_plus[`k',3]
	qui mat colnames p_plus = treat2
	qui est restore `x'
	qui mat foo=pt1,pt2
	qui mat foo2=p_stand,p_plus
	qui estadd matrix p_ri = foo
	qui estadd matrix p_rw = foo2

	qui eststo `x' 

	qui ritest treat  (_b[2.treat]/_se[2.treat]-_b[1.treat]/_se[1.treat]), seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)
	qui matrix p_t3=r(p)
	qui est restore `x'
	qui estadd scalar p_diff2=p_t3[1,1]
	qui estadd scalar p_diff3=RW_diff[`k',3]

	qui eststo `x' 
	local k=`k'+1

} 

estout  st_tot_letters* using "${JPE}/Draft/Tables/table_b8a.tex" ,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]))  p_ri(par(\{  \})) p_rw(par(( )))  .)  stats(p_diff p_diff2 p_diff3 obs clusters , layout("[@]" "\{@\}" "(@)"  "") fmt(%9.3f %9.3f %9.3f /*%9.3f*/  %9.0g ) labels("Original = Plus" " " " " ""   "Observations" "Clusters" ))  label collabels(none)  mlabels(none) varlabels(treat1 "API Standard"  treat2 "API Plus"  )   keep(treat*) 



qui rwolf2 (reg st_tot_num1_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num2_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num3_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4a_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4b_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num5_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num6_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)), cluster(cct) indepvars(treat1, treat1, treat1,treat1,treat1,treat1,treat1) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_stand=e(RW)

qui rwolf2 (reg st_tot_num1_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num2_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num3_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4a_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4b_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num5_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num6_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)), cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_plus=e(RW)



qui rwolf2(reg st_tot_num1_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num2_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num3_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4a_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num4b_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num5_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_tot_num6_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)), cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)	
mat RW_diff=e(RW)


local k=1

foreach x of varlist st_tot_num1_2_sd st_tot_num2_2_sd st_tot_num3_2_sd st_tot_num4a_2_sd st_tot_num4b_2_sd st_tot_num5_2_sd st_tot_num6_2_sd{
	qui reg `x' treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)			
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui estadd scalar adjR2 = e(r2_a)
	qui test treat1=treat2
	qui estadd scalar p_diff=r(p)
	qui sum `x' if e(sample) & treat==0
	qui estadd scalar mean = r(mean)
	qui estadd scalar sd=r(sd)
	qui eststo `x' 

	qui ritest treat _b[1.treat]/_se[1.treat] , fixlevels(2) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt1=r(p)
	qui mat colnames pt1 = treat1
	qui mat p_stand=RW_stand[`k',3]
	qui mat colnames p_stand = treat1
	
	qui ritest treat _b[2.treat]/_se[2.treat] , fixlevels(1) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt2=r(p)
	qui mat colnames pt2 = treat2 
	qui mat p_plus=RW_plus[`k',3]
	qui mat colnames p_plus = treat2
	qui est restore `x'
	qui mat foo=pt1,pt2
	qui mat foo2=p_stand,p_plus
	qui estadd matrix p_ri = foo
	qui estadd matrix p_rw = foo2

	qui eststo `x' 

	qui ritest treat  (_b[2.treat]/_se[2.treat]-_b[1.treat]/_se[1.treat]), seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)
	qui matrix p_t3=r(p)
	qui est restore `x'
	qui estadd scalar p_diff2=p_t3[1,1]
	qui estadd scalar p_diff3=RW_diff[`k',3]

	qui eststo `x' 
	local k=`k'+1

} 

estout  st_tot_num*  using "${JPE}/Draft/Tables/table_b8b.tex" ,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]))  p_ri(par(\{  \})) p_rw(par(( ))) .)  stats(p_diff p_diff2 p_diff3  obs clusters , layout("[@]" "\{@\}" "(@)"  "") fmt(%9.3f %9.3f %9.3f  %9.0g ) labels("Original = Plus" " " " " ""   "Observations" "Clusters" ))  label collabels(none)  mlabels(none) varlabels(treat1 "API Original"  treat2 "API Plus"  )   keep(treat*)

**************************************************************************************************
/* Table B-9: Average Program Impacts by the Individual Components of the Socio-Emotional Score */
**************************************************************************************************
use "${JPE}/Data/exp2.dta", clear

forvalues j = 0(1)2{
	gen treat`j' = 0
	replace treat`j' = 1 if treat==`j'
	replace treat`j' = . if treat==.
}

egen miss=rowmiss(st_dum_e1_2-st_dum_e32_2)
recode st_dum_e1_2-st_dum_e32_2 (.=0) if miss==32&merge_ind_par==3

local reps=3000
local seed=123

qui rwolf2 (reg st_dum_e1_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e2_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e3_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e4_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e5_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e6_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e7_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e8_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e9_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e10_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e11_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e12_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e13_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e14_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e15_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e16_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e17_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e18_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e19_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e20_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e21_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e22_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e23_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e24_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e25_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e26_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e27_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e28_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e29_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e30_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e31_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e32_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct))	, cluster(cct) indepvars(treat1, treat1, treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1, treat1, treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1,treat1) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_stand=e(RW)


qui rwolf2 (reg st_dum_e1_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e2_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e3_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e4_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e5_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e6_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e7_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e8_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e9_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e10_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e11_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e12_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e13_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e14_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e15_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e16_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e17_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e18_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e19_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e20_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e21_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e22_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e23_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e24_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e25_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e26_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e27_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e28_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e29_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e30_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e31_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e32_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct))	, cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_plus=e(RW)


qui rwolf2 (reg st_dum_e1_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e2_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e3_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e4_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e5_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e6_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e7_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e8_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e9_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e10_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e11_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e12_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e13_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e14_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e15_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e16_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e17_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e18_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e19_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e20_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e21_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e22_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e23_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e24_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e25_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e26_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e27_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e28_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e29_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e30_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e31_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct)) (reg st_dum_e32_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2   if merge_ind_par==3, cluster(cct))	, cluster(cct) indepvars(treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2, treat2, treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2,treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_diff=e(RW)



local k=1

foreach x of varlist st_dum_e1_2-st_dum_e32_2{
	qui reg `x' treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)			
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui estadd scalar adjR2 = e(r2_a)
	qui test treat1=treat2
	qui estadd scalar p_diff=r(p)
	qui sum `x' if e(sample) & treat==0
	qui estadd scalar mean = r(mean)
	qui estadd scalar sd=r(sd)
	qui eststo `x' 

	qui ritest treat _b[1.treat]/_se[1.treat] , fixlevels(2) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt1=r(p)
	qui mat colnames pt1 = treat1
	qui mat p_stand=RW_stand[`k',3]
	qui mat colnames p_stand = treat1

	
	qui ritest treat _b[2.treat]/_se[2.treat] , fixlevels(1) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt2=r(p)
	qui mat colnames pt2 = treat2 
	qui mat p_plus=RW_plus[`k',3]
	qui mat colnames p_plus = treat2
	qui est restore `x'
	qui mat foo=pt1,pt2
	qui mat foo2=p_stand,p_plus
	qui estadd matrix p_ri = foo
	qui estadd matrix p_rw = foo2

	qui eststo `x' 

	qui ritest treat  (_b[2.treat]/_se[2.treat]-_b[1.treat]/_se[1.treat]), seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)
	qui matrix p_t3=r(p)
	qui est restore `x'
	qui estadd scalar p_diff2=p_t3[1,1]
	qui estadd scalar p_diff3=RW_diff[`k',3]

	qui eststo `x' 
	local k=`k'+1

} 

estout  st_dum_e1_2 st_dum_e2_2 st_dum_e3_2 st_dum_e4_2 st_dum_e5_2 st_dum_e6_2 st_dum_e7_2 st_dum_e8_2 st_dum_e9_2 st_dum_e10_2 st_dum_e11_2 st_dum_e12_2 st_dum_e13_2 st_dum_e14_2 st_dum_e15_2 st_dum_e16_2 using "${JPE}/Draft/Tables/table_b9.tex" ,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]))  p_ri(par(\{  \})) p_rw(par(( ))) "") stats(p_diff p_diff2 p_diff3  obs clusters , layout("[@]" "\{@\}" "(@)"  "") fmt(%9.3f %9.3f %9.3f  %9.0g ) labels("Original = Plus" " " " " ""   "Observations" "Clusters" ))  label collabels(none)  mlabels(none) varlabels(treat1 "API Original"  treat2 "API Plus"  )   keep(treat*)


**************************************************************************
/* Table B10: Comparison of Mentors’ Characteristics Across Situations  */
**************************************************************************

use "${JPE}/Data/exp2.dta", clear
keep if mt_age_2!=.

keep mt_* treat cct
rename mt_age_2 age
rename mt_male_2 male

gen indigenous=(mt_P4_1_2!="NINGUNA")
keep age male indigenous treat cct

keep age male indigenous cct

gen sample_experiment = 1 

append using "${JPE}/Data/exp2_mentors_app.dta"

replace sample_experiment = 0 if sample_experiment==.

sum if sample_experiment==0
sum if sample_experiment==1

label variable male "Male"
label variable age "Age"
label variable indigenous "Speaks Indigenous Language"

balancetable (mean if sample_exp==0) (mean if sample_exp==1) (diff sample_experiment)  male age indig using "${JPE}/Draft/Tables/table_b10.tex",  varlabels pval par([])  vce(robust) ctitles("Chiapas sample" "Experiment 2" "Chiapas vs Experiment 2" ) replace
		  
	

*********************************************************************************************
/* Table B11: Change in Situation and Impacts on Quality and Quantity of Mentoring Program */
*********************************************************************************************
use "${JPE}/Data/scaleup_mentors.dta", clear
		
local varlist1 "API_staydays  LEC_API_activities API_lectime"
local varlist2 "risk_meetings studrez_API API_studtime "

foreach var in `varlist1'{	

egen mean_`var' = mean(`var'), by(cct post)
bysort cct post: gen obs_cct = _n

reg mean_`var' treatment i.sc_strata i.sc_criterios_3 i.sc_criterios_4 i.treat IM_2010_final  confl_sum if obs_cct==1, cluster(cct)		
gen sample = e(sample)
qui estadd scalar obs = e(N)
qui sum mean_`var' if sample  & treatment==0
qui estadd scalar obs_2016 = r(N)
qui sum mean_`var' if sample  & treatment==1
qui estadd scalar obs_2018 = r(N)

estimates store quant_d_`var'
drop obs_cct sample

}

foreach var in `varlist2'{	

egen mean_`var' = mean(`var'), by(cct post)
bysort cct post: gen obs_cct = _n

reg mean_`var' treatment i.sc_strata i.sc_criterios_3 i.sc_criterios_4 i.treat IM_2010_final  confl_sum if obs_cct==1, cluster(cct)	
gen sample = e(sample)	
qui estadd scalar obs = e(N)
qui sum mean_`var' if sample & treatment==0
qui estadd scalar obs_2016 = r(N)
qui sum mean_`var' if sample & treatment==1
qui estadd scalar obs_2018 = r(N)

estimates store qual_d_`var'
drop obs_cct sample

}

estout  quant_d_* qual_d_* using "${JPE}/Draft/Tables/table_b11.tex" ,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]) fmt(%9.3f)) .)  stats(obs obs_2016 obs_2018 , fmt(%9.0g %9.0g ) labels("Observations" "Observations Survey 2016" "Observations Survey 2018"))  label collabels(none)  mlabels(none) varlabels(treatment "Change in Situation"  )   keep(treatment) 

***********************************************************************
/* Table B-12: The Impact of the API Plus Program on School Closures */
***********************************************************************
use "${JPE}/Data/scaleup.dta", clear

gen school_close_def2020 = 1-open2019


qui reg school_close_def2020 api_1718_new i.treat confl_sum i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if expe==1 &enr_sec_2020!=.  , r
qui estadd scalar obs = e(N)
qui sum school_close_def2020 if e(sample), de 
qui estadd scalar mean = r(mean)
eststo est_closure_exp


qui reg school_close_def2020 api_1718_new confl_sum  i.api_original_2015 i.(criterio1_1617 criterio2_1617 criterio3_1617 criterio4_1617 criterio5_1617 criterio1_1718 criterio2_1718 criterio3_1718 criterio4_1718 criterio5_1718) if exp==0&up==1  &enr_sec_2020!=., r
qui estadd scalar obs = e(N)
qui sum school_close_def2020 if e(sample), de 
qui estadd scalar mean = r(mean)
eststo est_closure_noexp


estout   est_closure_noexp est_closure_exp using "${JPE}/Draft/Tables/table_b12.tex" ,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]) fmt(%9.3f)) .)  stats(obs , fmt(%9.0g %9.0g ) labels("Observations"))  label collabels(none)  mlabels(none) varlabels(api_1718_new "API Plus"  )   keep(api_1718_new) 

**********************************************************************************************
/* Table B-13: Average Program Impacts by the Individual Components of Parental Investments */
**********************************************************************************************

* Panel A: First Experiment
use "${JPE}/Data/exp1_parents.dta", clear

global regressors3 "i.enti parent_male"
global covar_par "parent_indig parent_male enl_spanish_2010 enl_math_2010 i.enti"

gen parent_indig=P04_1!=0

gen parent_male=1 if P02==1
replace parent_male=0 if P02==2

gen parent_age=P03
replace parent_age=999 if P03==.

gen missage=(parent_age==999)

foreach var of varlist P17 P21_1 P21_2 P21_3 P21_4 P22_1 P22_2 P22_3 P22_4 P22_5 P22_6 P22_7 {
gen d`var'=1 if `var'==1
replace d`var'=0 if `var'==2
}


rename P16 p_help_hw_2
rename dP17 p_academic_extra_2

rename dP21_1 p_work_for_school_2
rename dP21_2 p_donate_money_2
rename dP21_3 p_manage_resources_2
rename dP21_4 p_donate_in_kind_2
rename dP22_1 p_propose_material_2
rename dP22_2 p_decide_material_2
rename dP22_5 p_evaluate_targets_2
rename dP22_6 p_money_alloc_2
rename dP22_7 p_feeding_LEC_2
rename P18 p_meet_teach_2
rename P19 books
rename P20 read_child

gen p_expec_bac_more_2=(P13>=3 & P13<=6)
replace p_expec_bac_more_2=. if P13>9


foreach x in  p_meet_teach_2 {
	qui sum `x' if treat==0 
	gen `x'_sd = (`x' - r(mean))/r(sd)
}


local reps=3000
local seed=123
qui rwolf2 (reg p_work_for_school_2 treat $covar_par, vce(cl ID02)) (reg p_donate_money_2 treat $covar_par, vce(cl ID02)) (reg p_donate_in_kind_2 treat $covar_par, vce(cl ID02)) (reg p_feeding_LEC_2 treat $covar_par, vce(cl ID02)) (reg p_manage_resources_2 treat $covar_par, vce(cl ID02)) (reg p_propose_material_2 treat $covar_par, vce(cl ID02)) (reg p_decide_material_2 treat $covar_par, vce(cl ID02)) (reg p_money_alloc_2 treat $covar_par, vce(cl ID02)) (reg p_evaluate_targets_2 treat $covar_par, vce(cl ID02)) (reg p_help_hw_2 treat $covar_par, vce(cl ID02)) (reg p_academic_extra_2 treat $covar_par, vce(cl ID02)) (reg p_meet_teach_2_sd treat $covar_par, vce(cl ID02)) (reg p_expec_bac_more_2 treat $covar_par, vce(cl ID02)), cluster(ID02) indepvars(treat, treat, treat, treat, treat, treat, treat, treat, treat, treat, treat, treat, treat) usevalid seed(`seed') reps(`reps') nodots strata(enti)
mat RW_treat=e(RW)



local k=1

foreach var in  p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2 p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2 p_help_hw_2 p_academic_extra_2 p_meet_teach_2_sd  p_expec_bac_more_2 {

qui reg `var' treat $covar_par, cluster(ID02)
	qui mat p_rw = RW_treat[`k',3]
	qui mat colnames p_rw = treat
	qui estadd matrix p_rw 
	qui sum `var' if treat==0
	qui eret2 scalar mean=r(mean)
	qui eret2 scalar sd=r(sd)
	qui eststo `var'

	qui ritest treat _b[treat]/_se[treat] , seed(`seed') reps(`reps') nodots cluster(ID02)  strata(enti): reg `var' treat $covar_par, cluster(ID02)
	
	qui matrix p_ri=r(p)
	qui mat colnames p_ri = treat
	qui est restore `var'

	qui estadd matrix p_ri

	qui eststo `var' 

	local k=`k'+1
}

estout p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2 p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2 p_help_hw_2 p_academic_extra_2 p_meet_teach_2_sd  p_expec_bac_more_2 using "${JPE}/Draft/Tables/table_b13a.tex", replace style(tex) cells(b(star fmt(%9.3f)) p(par([ ])) p_ri(par(\{  \})) p_rw(par(( ))) .)  stats(N_clust N, fmt(%9.0f) label( "Number of clusters" "Observations")) label collabels(none) mlabels(none) varlabels(treat "API Original")   keep(treat)



* Panel B: Second Experiment
use "${JPE}/Data/exp2.dta", clear
forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

qui reg st_egra_2 treat1 treat2 i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)			
gen est_sample = e(sample)

foreach x in p_meet_teach_2 {
	qui sum `x' if treat==0&est_sample==1
	gen `x'_sd = (`x' - r(mean))/r(sd)
}

ren p_manage_school_resources_2 p_manage_resources_2
ren p_propose_school_material_2 p_propose_material_2
ren p_decide_school_material_2 p_decide_material_2
ren p_decide_money_alloc_2 p_money_alloc_2

local reps=3000
local seed=123

* Romano-Wolf FWER
qui rwolf2 (reg p_work_for_school_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_money_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_in_kind_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_feeding_LEC_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_manage_resources_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_propose_material_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_decide_material_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_money_alloc_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_evaluate_targets_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_help_hw_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_academic_extra_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_meet_teach_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_expec_bac_more_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)), cluster(cct) indepvars(treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1, treat1) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_stand=e(RW)

qui rwolf2 (reg p_work_for_school_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_money_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_in_kind_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_feeding_LEC_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_manage_resources_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_propose_material_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_decide_material_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_money_alloc_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_evaluate_targets_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_help_hw_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_academic_extra_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_meet_teach_2_sd treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_expec_bac_more_2 treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)), cluster(cct) indepvars(treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_plus=e(RW)


qui rwolf2 (reg p_work_for_school_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_money_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_donate_in_kind_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_feeding_LEC_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_manage_resources_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_propose_material_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_decide_material_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_money_alloc_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_evaluate_targets_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_help_hw_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_academic_extra_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_meet_teach_2_sd treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)) (reg p_expec_bac_more_2 treat0 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2  if merge_ind_par==3, vce(cl cct)), cluster(cct) indepvars(treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2, treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_diff=e(RW)

local k=1

foreach x in  p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2 p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2 p_help_hw_2 p_academic_extra_2 p_meet_teach_2_sd  p_expec_bac_more_2 {
	qui reg `x' treat1 treat2 st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)			
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui estadd scalar adjR2 = e(r2_a)
	qui test treat1=treat2
	qui estadd scalar p_diff=r(p)
	qui sum `x' if e(sample) & treat==0
	qui estadd scalar mean = r(mean)
	qui estadd scalar sd=r(sd)
	qui eststo `x' 

	qui ritest treat _b[1.treat]/_se[1.treat] , fixlevels(2) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt1=r(p)
	qui mat colnames pt1 = treat1
	qui mat p_stand=RW_stand[`k',3]
	qui mat colnames p_stand = treat1

	qui ritest treat _b[2.treat]/_se[2.treat] , fixlevels(1) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2  i.st_num_ruta_2   if merge_ind_par==3, vce(cl cct)
	qui matrix pt2=r(p)
	qui mat colnames pt2 = treat2 
	qui mat p_plus=RW_plus[`k',3]
	qui mat colnames p_plus = treat2
	qui est restore `x'
	qui mat foo=pt1,pt2
	qui mat foo2=p_stand,p_plus
	qui estadd matrix p_ri = foo
	qui estadd matrix p_rw = foo2
	qui eststo `x' 

	qui ritest treat  (_b[2.treat]/_se[2.treat]-_b[1.treat]/_se[1.treat]), seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg `x' i.treat st_male_2  st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)
	qui matrix p_t3=r(p)
	qui est restore `x'
	qui estadd scalar p_diff2=p_t3[1,1]
	qui estadd scalar p_diff3=RW_diff[`k',3]

	qui eststo `x' 
	local k=`k'+1

} 

estout  p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2 p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2 p_help_hw_2 p_academic_extra_2 p_meet_teach_2_sd  p_expec_bac_more_2 /*using "${JPE}/Draft/Tables/table_b13b.tex"*/,  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]) fmt(%9.3f)) p_ri(par(\{ \}) fmt(%9.3f))  p_rw(par(( )) fmt(%9.3f))  .)  stats(p_diff p_diff2 p_diff3   obs clusters , layout("[@]" "\{@\}" "(@)"  "") fmt(%9.3f %9.3f %9.3f  %9.0g ) labels("Original = Plus" " " " " "" "Observations" "Clusters" ))  label collabels(none)  mlabels(none) varlabels(treat1 "API Original"  treat2 "API Plus"  )   keep(treat*) 

*********************************************
/* Table B-14: Remedial Education Sessions */
*********************************************

use "${JPE}/Data/exp2.dta", clear

ren st_st_spanishscore_1_2 st_spanishscore_1 
ren st_st_mathscore_1_2 st_mathscore_1 
ren st_st_natsciences_1_2 st_natscore_1

local list1 "st_spanishscore_1 st_mathscore_1 st_natscore_1" 

egen mean_score=rowmean(`list1')
gen miss_score=(mean_score==.)
** We generate the ranking before replacing the missing - otherwise the value assigned to the missing might affect the ranking **
bys cct: egen rank_avg=rank(mean_score), track
gen miss_rank=(rank_avg==.)
label var rank_avg "Rank"

forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

swindex st_egra_2 st_egma_2 st_tot_dum_e_2 if merge_ind_par==3, gen(st_index_2)

swindex p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2, generate(p_engage_school)

ren p_manage_school_resources_2 p_manage_resources_2
ren p_propose_school_material_2 p_propose_material_2
ren p_decide_school_material_2 p_decide_material_2
ren p_decide_money_alloc_2 p_money_alloc_2
swindex p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2, generate(p_engage_manage)

swindex p_help_hw_2 p_academic_extra_2 p_meet_teach_2  p_expec_bac_more_2, generate(p_engage_child)

swindex p_work_for_school_2 p_donate_money_2 p_donate_in_kind_2 p_feeding_LEC_2 p_manage_resources_2 p_propose_material_2 p_decide_material_2 p_money_alloc_2   p_evaluate_targets_2 p_help_hw_2 p_academic_extra_2 p_meet_teach_2  p_expec_bac_more_2, generate(p_engage_all)


foreach x of varlist p_engage_school  p_engage_manage  p_engage_child p_engage_all p_meet_teach_2 st_egra_2 st_egma_2 st_tot_dum_e_2 st_index_2 {
	gen `x'_sd = .
	qui sum `x' if treat==0  & merge_ind_par==3
	replace `x'_sd =(`x'-r(mean))/r(sd) 
	}

gen below7=(rank_avg<7)
gen miss7=(rank_avg==.)
label var below7 "Rank of average score below 7"

gen treat1miss7=treat1*miss7
gen treat2miss7=treat2*miss7

gen treat1below7=treat1*below7
gen treat2below7=treat2*below7

gen treat1above7=treat1*(1-below7)
gen treat2above7=treat2*(1-below7)



foreach x of varlist st_egra_2_sd st_egma_2_sd st_tot_dum_e_2_sd st_index_2_sd p_engage_school  p_engage_manage  p_engage_child p_engage_all {
label var treat1 "API Standard" 
label var treat2 "API Plus" 
qui xi: reg `x' treat1above7 treat2above7 below7 treat1below7 treat2below7 treat1miss7 treat2miss7 miss7  /*mean_score   mean_score_sq*/  st_male_2 st_ind_lang_2 sc_cal_* i.sc_strata1_0 i.st_week_int_2 i.st_num_ruta_2 if merge_ind_par==3, vce(cl cct)
qui estadd scalar obs = e(N)
qui estadd scalar clusters = e(N_clust)
qui test treat1below7=treat2below7
qui estadd scalar pval_tb=r(p)
qui test treat1above7=treat2above7
qui estadd scalar pval_ta=r(p)
qui test (treat2below7-treat2above7)=(treat1below7-treat1above7)
qui estadd scalar pval_plus=r(p)
qui sum `x' if e(sample) & treat==0
qui estadd scalar mean = r(mean)
qui estadd scalar sd=r(sd)
eststo `x'  
}


estout st_egra_2* st_egma_2* st_tot_dum_e_2* st_index_2_* using "${JPE}/Draft/Tables/table_b14.tex", replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ])) .) stats(pval_tb pval_ta pval_plus  obs clusters, layout("[@]" "[@]" "[@]"  "") fmt(%9.3f %9.3f %9.3f %9.0g %9.0g) labels("H0: Original=Plus ($<$7)" "H0: Original=Plus ($\geq$7)" "H0: [Original-Plus ($<$7)]=[Original-Plus ($\geq$7)]" "" "Observations" "Clusters")) starlevels(* 0.10 ** 0.05 *** 0.01) label collabels(none)     mlabels(none) varlabels(treat1above7 "API Original$\times$ Rank$\geq$7"  treat2above7 "API Plus$\times$ Rank$\geq$7" treat1below7 "API Original$\times$ Rank$<$7" treat2below7 "API Plus$\times$ Rank$<$7")   keep(treat1above7 treat2above7 treat1below7 treat2below7)  order(treat1above7 treat2above7  treat1below7 treat2below7)

***********************************************
/* Table B-15: Teacher Pedagogical Practices */
***********************************************
use "${JPE}/Data/exp2.dta", clear

forvalues j = 0(1)2{
gen treat`j' = 0
replace treat`j' = 1 if treat==`j'
replace treat`j' = . if treat==.
}

gen second_obs=l_NUM_OBS==2

bys cct: egen tp_st_week_int_2=max(st_week_int_2)
bys cct: egen tp_st_num_ruta_2=max(st_num_ruta_2)

gen l_minutes_times_out_2 = 60*l_times_out_2/20

foreach x of varlist l_times_out_2 l_activity_sw_2 l_interact_sw_2  l_manage_sw_2 l_material_sw_2 l_teach_sw_2 l_teach2_sw_2     {

gen `x'_sd = .
sum `x' if (treat==0)
replace `x'_sd =(`x'-r(mean))/r(sd)
}

egen miss=rowmiss(sc_totalalumnos_1  sc_cal_* sc_strata1_0) if l_activity_pca_2!=.
replace miss=miss>0 if l_activity_pca_2!=.
foreach var of varlist sc_totalalumnos_1  sc_cal_* sc_strata1_0 {
	recode `var' .=0 if l_activity_pca_2!=.
}

collapse l_activity_sw_2_sd l_interact_sw_2_sd  l_manage_sw_2_sd l_material_sw_2_sd l_teach2_sw_2_sd treat treat0 treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  tp_st_week_int_2  tp_st_num_ruta_2 sc_strata1_0, by(cct)

local reps=3000
local seed=123
qui rwolf2 (reg l_activity_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, r) (reg l_interact_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, r) (reg l_manage_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, r) (reg l_material_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, r) (reg l_teach2_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, r), indepvars(treat1, treat1, treat1, treat1, treat1) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_stand=e(RW)

qui rwolf2 (reg l_activity_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_interact_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_manage_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_material_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_teach2_sw_2_sd treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)), indepvars(treat2, treat2, treat2, treat2, treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)

mat RW_plus=e(RW)

qui rwolf2 (reg l_activity_sw_2_sd treat0 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_interact_sw_2_sd treat0 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_manage_sw_2_sd treat0 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_material_sw_2_sd treat0 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)) (reg l_teach2_sw_2_sd treat0 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)), indepvars(treat2, treat2, treat2, treat2, treat2) usevalid seed(`seed') reps(`reps') nodots strata(sc_strata1_0)
mat RW_diff=e(RW)

local k=1

foreach x in activity_sw interact_sw  manage_sw material_sw teach2_sw   {
	qui reg l_`x'_2_sd  treat1 treat2 l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)			
	qui estadd scalar obs = e(N)
	qui estadd scalar clusters = e(N_clust)
	qui estadd scalar adjR2 = e(r2_a)
	qui test treat1=treat2
	qui estadd scalar p_diff=r(p)
	qui sum l_`x'_2_sd if e(sample) & treat==0
	qui estadd scalar mean = r(mean)
	qui estadd scalar sd=r(sd)
	qui eststo `x' 

	qui ritest treat _b[1.treat]/_se[1.treat] , fixlevels(2) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg l_`x'_2_sd i.treat l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)
	qui matrix pt1=r(p)
	qui mat colnames pt1 = treat1
	qui mat p_stand=RW_stand[`k',3]
	qui mat colnames p_stand = treat1

	qui ritest treat _b[2.treat]/_se[2.treat] , fixlevels(1) seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg l_`x'_2_sd i.treat l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)
	qui matrix pt2=r(p)
	qui mat colnames pt2 = treat2 
	qui mat p_plus=RW_plus[`k',3]
	qui mat colnames p_plus = treat2
	qui est restore `x'
	qui mat foo=pt1,pt2
	qui mat foo2=p_stand,p_plus
	qui estadd matrix p_ri = foo
	qui estadd matrix p_rw = foo2
	qui eststo `x' 

	qui ritest treat  (_b[2.treat]/_se[2.treat]-_b[1.treat]/_se[1.treat]), seed(`seed') reps(`reps') nodots cluster(cct)  strata(sc_strata1_0): reg l_`x'_2_sd i.treat l_spanish_lesson_2 l_math_lesson_2 second_obs sc_totalalumnos_1  sc_cal_*  i.tp_st_week_int_2  i.tp_st_num_ruta_2 i.sc_strata1_0, vce(cl cct)
	qui matrix p_t3=r(p)
	qui est restore `x'
	qui estadd scalar p_diff2=p_t3[1,1]
	qui estadd scalar p_diff3=RW_diff[`k',3]

	qui eststo `x' 
	local k=`k'+1

} 

estout  activity_sw interact_sw  manage_sw material_sw teach2_sw using "${JPE}/Draft/Tables/table_b15.tex",  replace style(tex) cells(b(nostar fmt(%9.3f)) p(par([ ]))  p_ri(par(\{  \})) p_rw(par(( ))) .)  stats(p_diff p_diff2 p_diff3    obs , layout("[@]" "\{@\}" "(@)"  "") fmt(%9.3f %9.3f %9.3f  %9.0g ) labels("Original = Plus" " " " "  "" "Observations"))  label collabels(none)  mlabels(none) varlabels(treat1 "API \textit{Original}"  treat2 "API \textit{Plus}"  )   keep(treat*) 


